home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / game / shoot / ADoom_src_1_1.lha / ADoom_src / g_game.c < prev    next >
C/C++ Source or Header  |  1998-02-15  |  36KB  |  1,692 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:  none
  20. //
  21. //-----------------------------------------------------------------------------
  22.  
  23.  
  24. static const char
  25. rcsid[] = "$Id: g_game.c,v 1.8 1997/02/03 22:45:09 b1 Exp $";
  26.  
  27. #include <string.h>
  28. #include <stdlib.h>
  29.  
  30. #include "doomdef.h" 
  31. #include "doomstat.h"
  32.  
  33. #include "z_zone.h"
  34. #include "f_finale.h"
  35. #include "m_argv.h"
  36. #include "m_misc.h"
  37. #include "m_menu.h"
  38. #include "m_random.h"
  39. #include "i_system.h"
  40.  
  41. #include "p_setup.h"
  42. #include "p_saveg.h"
  43. #include "p_tick.h"
  44.  
  45. #include "d_main.h"
  46.  
  47. #include "wi_stuff.h"
  48. #include "hu_stuff.h"
  49. #include "st_stuff.h"
  50. #include "am_map.h"
  51.  
  52. // Needs access to LFB.
  53. #include "v_video.h"
  54.  
  55. #include "w_wad.h"
  56.  
  57. #include "p_local.h" 
  58.  
  59. #include "s_sound.h"
  60.  
  61. // Data.
  62. #include "dstrings.h"
  63. #include "sounds.h"
  64.  
  65. // SKY handling - still the wrong place.
  66. #include "r_data.h"
  67. #include "r_sky.h"
  68.  
  69.  
  70.  
  71. #include "g_game.h"
  72.  
  73.  
  74. //#define SAVEGAMESIZE    0x2c000
  75. #define SAVEGAMESIZE    0x50000
  76. #define SAVESTRINGSIZE    24
  77.  
  78.  
  79.  
  80. boolean    G_CheckDemoStatus (void); 
  81. void    G_ReadDemoTiccmd (ticcmd_t* cmd); 
  82. void    G_WriteDemoTiccmd (ticcmd_t* cmd); 
  83. void    G_PlayerReborn (int player); 
  84. void    G_InitNew (skill_t skill, int episode, int map); 
  85.  
  86. void    G_DoReborn (int playernum); 
  87.  
  88. void    G_DoLoadLevel (void); 
  89. void    G_DoNewGame (void); 
  90. void    G_DoLoadGame (void); 
  91. void    G_DoPlayDemo (void); 
  92. void    G_DoCompleted (void); 
  93. void    G_DoVictory (void); 
  94. void    G_DoWorldDone (void); 
  95. void    G_DoSaveGame (void); 
  96.  
  97.  
  98. gameaction_t    gameaction; 
  99. gamestate_t     gamestate; 
  100. skill_t         gameskill; 
  101. boolean        respawnmonsters;
  102. int             gameepisode; 
  103. int             gamemap; 
  104.  
  105. boolean         paused; 
  106. boolean         sendpause;                 // send a pause event next tic 
  107. boolean         sendsave;                 // send a save event next tic 
  108. boolean         usergame;               // ok to save / end game 
  109.  
  110. boolean         timingdemo;             // if true, exit with report on completion 
  111. boolean         nodrawers;              // for comparative timing purposes 
  112. boolean         noblit;                 // for comparative timing purposes 
  113. int             starttime;              // for comparative timing purposes       
  114.  
  115. boolean         viewactive; 
  116.  
  117. boolean         deathmatch;               // only if started as net death 
  118. boolean         netgame;                // only true if packets are broadcast 
  119. boolean         playeringame[MAXPLAYERS]; 
  120. player_t        players[MAXPLAYERS]; 
  121.  
  122. int             consoleplayer;          // player taking events and displaying 
  123. int             displayplayer;          // view being displayed 
  124. int             gametic; 
  125. int             levelstarttic;          // gametic at level start 
  126. int             totalkills, totalitems, totalsecret;    // for intermission 
  127.  
  128. char            demoname[32]; 
  129. boolean         demorecording; 
  130. boolean         demoplayback; 
  131. boolean        netdemo; 
  132. byte*        demobuffer;
  133. byte*        demo_p;
  134. byte*        demoend; 
  135. boolean         singledemo;                // quit after playing a demo from cmdline 
  136.  
  137. boolean         precache = true;        // if true, load all graphics at start 
  138.  
  139. wbstartstruct_t wminfo;                   // parms for world map / intermission 
  140.  
  141. short        consistancy[MAXPLAYERS][BACKUPTICS]; 
  142.  
  143. byte*        savebuffer;
  144.  
  145.  
  146. // 
  147. // controls (have defaults) 
  148. // 
  149. int             key_right;
  150. int        key_left;
  151.  
  152. int        key_up;
  153. int        key_down; 
  154. int             key_strafeleft;
  155. int        key_straferight; 
  156. int             key_fire;
  157. int        key_use;
  158. int        key_strafe;
  159. int        key_speed; 
  160.  
  161. int             mousebfire; 
  162. int             mousebstrafe; 
  163. int             mousebforward; 
  164.  
  165. int             joybfire; 
  166. int             joybstrafe; 
  167. int             joybuse; 
  168. int             joybspeed; 
  169.  
  170.  
  171.  
  172. #define MAXPLMOVE        (forwardmove[1]) 
  173.  
  174. #define TURBOTHRESHOLD    0x32
  175.  
  176. fixed_t        forwardmove[2] = {0x19, 0x32}; 
  177. fixed_t        sidemove[2] = {0x18, 0x28}; 
  178. fixed_t        angleturn[3] = {640, 1280, 320};    // + slow turn 
  179.  
  180. #define SLOWTURNTICS    6 
  181.  
  182. #define NUMKEYS        256 
  183.  
  184. boolean         gamekeydown[NUMKEYS]; 
  185. int             turnheld;                // for accelerative turning 
  186.  
  187. boolean        mousearray[4]; 
  188. boolean*    mousebuttons = &mousearray[1];        // allow [-1]
  189.  
  190. // mouse values are used once 
  191. int             mousex;
  192. int        mousey;         
  193.  
  194. int             dclicktime;
  195. int        dclickstate;
  196. int        dclicks; 
  197. int             dclicktime2;
  198. int        dclickstate2;
  199. int        dclicks2;
  200.  
  201. // joystick values are repeated 
  202. int             joyxmove;
  203. int        joyymove;
  204. boolean         joyarray[5]; 
  205. boolean*    joybuttons = &joyarray[1];        // allow [-1] 
  206.  
  207. int        savegameslot; 
  208. char        savedescription[32]; 
  209.  
  210.  
  211. #define    BODYQUESIZE    32
  212.  
  213. mobj_t*        bodyque[BODYQUESIZE]; 
  214. int        bodyqueslot; 
  215.  
  216. void*        statcopy;                // for statistics driver
  217.  
  218.  
  219.  
  220. int G_CmdChecksum (ticcmd_t* cmd) 
  221.     int        i;
  222.     int        sum = 0; 
  223.      
  224.     for (i=0 ; i< sizeof(*cmd)/4 - 1 ; i++) 
  225.     sum += ((int *)cmd)[i]; 
  226.          
  227.     return sum; 
  228.  
  229.  
  230. //
  231. // G_BuildTiccmd
  232. // Builds a ticcmd from all of the available inputs
  233. // or reads it from the demo buffer. 
  234. // If recording a demo, write it out 
  235. // 
  236. void G_BuildTiccmd (ticcmd_t* cmd) 
  237.     int        i; 
  238.     boolean    strafe;
  239.     boolean    bstrafe; 
  240.     int        speed;
  241.     int        tspeed; 
  242.     int        forward;
  243.     int        side;
  244.     
  245.     ticcmd_t*    base;
  246.  
  247.     base = I_BaseTiccmd ();        // empty, or external driver
  248.     memcpy (cmd,base,sizeof(*cmd)); 
  249.     
  250.     cmd->consistancy = 
  251.     consistancy[consoleplayer][maketic%BACKUPTICS]; 
  252.  
  253.  
  254.     strafe = gamekeydown[key_strafe] || mousebuttons[mousebstrafe] 
  255.     || joybuttons[joybstrafe]; 
  256.     speed = gamekeydown[key_speed] || joybuttons[joybspeed];
  257.  
  258.     forward = side = 0;
  259.     
  260.     // use two stage accelerative turning
  261.     // on the keyboard and joystick
  262.     if (joyxmove < 0
  263.     || joyxmove > 0  
  264.     || gamekeydown[key_right]
  265.     || gamekeydown[key_left]) 
  266.     turnheld += ticdup; 
  267.     else 
  268.     turnheld = 0; 
  269.  
  270.     if (turnheld < SLOWTURNTICS) 
  271.     tspeed = 2;             // slow turn 
  272.     else 
  273.     tspeed = speed;
  274.     
  275.     // let movement keys cancel each other out
  276.     if (strafe) 
  277.     { 
  278.     if (gamekeydown[key_right]) 
  279.     {
  280.         // fprintf(stderr, "strafe right\n");
  281.         side += sidemove[speed]; 
  282.     }
  283.     if (gamekeydown[key_left]) 
  284.     {
  285.         //    fprintf(stderr, "strafe left\n");
  286.         side -= sidemove[speed]; 
  287.     }
  288.     if (joyxmove > 0) 
  289.         side += sidemove[speed]; 
  290.     if (joyxmove < 0) 
  291.         side -= sidemove[speed]; 
  292.  
  293.     } 
  294.     else 
  295.     { 
  296.     if (gamekeydown[key_right]) 
  297.         cmd->angleturn -= angleturn[tspeed]; 
  298.     if (gamekeydown[key_left]) 
  299.         cmd->angleturn += angleturn[tspeed]; 
  300.     if (joyxmove > 0) 
  301.         cmd->angleturn -= angleturn[tspeed]; 
  302.     if (joyxmove < 0) 
  303.         cmd->angleturn += angleturn[tspeed]; 
  304.     } 
  305.  
  306.     if (gamekeydown[key_up]) 
  307.     {
  308.     // fprintf(stderr, "up\n");
  309.     forward += forwardmove[speed]; 
  310.     }
  311.     if (gamekeydown[key_down]) 
  312.     {
  313.     // fprintf(stderr, "down\n");
  314.     forward -= forwardmove[speed]; 
  315.     }
  316.     if (joyymove < 0) 
  317.     forward += forwardmove[speed]; 
  318.     if (joyymove > 0) 
  319.     forward -= forwardmove[speed]; 
  320.     if (gamekeydown[key_straferight]) 
  321.     side += sidemove[speed]; 
  322.     if (gamekeydown[key_strafeleft]) 
  323.     side -= sidemove[speed];
  324.     
  325.     // buttons
  326.     cmd->chatchar = HU_dequeueChatChar(); 
  327.  
  328.     if (gamekeydown[key_fire] || mousebuttons[mousebfire] 
  329.     || joybuttons[joybfire]) 
  330.     cmd->buttons |= BT_ATTACK; 
  331.  
  332.     if (gamekeydown[key_use] || joybuttons[joybuse] ) 
  333.     { 
  334.     cmd->buttons |= BT_USE;
  335.     // clear double clicks if hit use button 
  336.     dclicks = 0;                   
  337.     } 
  338.  
  339.     // chainsaw overrides 
  340.     for (i=0 ; i<NUMWEAPONS-1 ; i++)        
  341.     if (gamekeydown['1'+i]) 
  342.     { 
  343.         cmd->buttons |= BT_CHANGE; 
  344.         cmd->buttons |= i<<BT_WEAPONSHIFT; 
  345.         break; 
  346.     }
  347.     
  348.     // mouse
  349.     if (mousebuttons[mousebforward]) 
  350.     forward += forwa